/**
 * Created by szx on 2018-01-27.
 */
var TcyDetailContrls = angular.module('TcyDetailContrls', []);//申明自定义模块

TcyDetailContrls.controller('TcyDetailCtrl', ['$scope','$routeParams', function ($scope,$routeParams) {
    $scope.CxsName=$routeParams.CxsName;
    $scope.type="all";
    $scope.issueDate="1";//1:最近一年，2：最近半年
    $scope.cycle="1";

    //获取数据源
    $scope.GetDataSource=function(){
        $.ajax({
            type: 'Get',
            url: './Data/cxs.json',
            data: {CxsName:$scope.CxsName,type:$scope.type,issueDate:$scope.issueDate,cycle:$scope.cycle},
            dataType: 'json',
            contentType: "application/json",
            success: function (data) {
                $scope.$apply(function () {
                    $scope.Model=data;

                    $scope.initChart();
                });
            }
        });
    }
    $scope.GetDataSource();


    $scope.changeWhereStr=function (value) {
        $scope.type=value;

        $scope.GetDataSource();
    }
    $scope.changeWhereStr2=function (value) {
        $scope.issueDate=value;

        $scope.GetDataSource();
    }
    $scope.changeWhereStr3=function (value) {
        $scope.cycle=value;

        $scope.GetDataSource();
    }


    //echart初始化
    $scope.initChart=function () {
        var myChart = echarts.init(document.getElementById('cxsDetailChart'));
        var option = {
            title : {
                text: '近期利率分布',
                subtext: '数据来源：薄记建档系统&一号通系统'
            },
            grid: {
                left: '3%',
                right: '7%',
                bottom: '3%',
                containLabel: true
            },
            tooltip : {
                // trigger: 'axis',
                showDelay : 0,
                formatter : function (params) {
                    return  params.seriesName + ' :<br/>'
                        + '债券简称：中信证券 <br/>'
                        + '簿记管理人：王维 <br/>'
                        + '发行利率：5.6% <br/>'
                        + '期限：1Y <br/>';
                    // if (params.value.length > 1) {
                    //     return params.seriesName + ' :<br/>'
                    //         + params.value[0] + '月 '
                    //         + params.value[1] + '% ';
                    // }
                    // else {
                    //     return params.seriesName + ' :<br/>'
                    //         + params.name + ' : '
                    //         + params.value + '% ';
                    // }
                },
                axisPointer:{
                    show: true,
                    type : 'cross',
                    lineStyle: {
                        type : 'dashed',
                        width : 1
                    }
                }
            },
            toolbox: {
                feature: {
                    dataZoom: {},
                    brush: {
                        type: ['rect', 'polygon', 'clear']
                    }
                }
            },
            brush: {
            },
            legend: {
                data: ['我的','其他'],
                left: 'center'
            },
            xAxis : [
                {
                    type : 'value',
                    scale:true,
                    axisLabel : {
                        formatter: '{value} 月'
                    },
                    splitLine: {
                        show: false
                    }
                }
            ],
            yAxis : [
                {
                    type : 'value',
                    scale:true,
                    axisLabel : {
                        formatter: '{value} %'
                    },
                    splitLine: {
                        show: false
                    }
                }
            ],
            series : [
                {
                    name:'我的',
                    type:'scatter',
                    data: $scope.Model.myData,
                    markArea: {
                        silent: true,
                        itemStyle: {
                            normal: {
                                color: 'transparent',
                                borderWidth: 1,
                                borderType: 'dashed'
                            }
                        },
                        data: [[{
                            name: '我的分布区间',
                            xAxis: 'min',
                            yAxis: 'min'
                        }, {
                            xAxis: 'max',
                            yAxis: 'max'
                        }]]
                    },
                    markPoint : {
                        data : [
                            {type : 'max', name: '最大值'},
                            {type : 'min', name: '最小值'}
                        ]
                    },
                    markLine : {
                        lineStyle: {
                            normal: {
                                type: 'solid'
                            }
                        },
                        data : [
                            {type : 'average', name: '平均值'},
                            { xAxis: 160 }
                        ]
                    }
                },
                {
                    name:'其他',
                    type:'scatter',
                    data: $scope.Model.qtData,
                    markArea: {
                        silent: true,
                        itemStyle: {
                            normal: {
                                color: 'transparent',
                                borderWidth: 1,
                                borderType: 'dashed'
                            }
                        },
                        data: [[{
                            name: '其他分布区间',
                            xAxis: 'min',
                            yAxis: 'min'
                        }, {
                            xAxis: 'max',
                            yAxis: 'max'
                        }]]
                    },
                    markPoint : {
                        data : [
                            {type : 'max', name: '最大值'},
                            {type : 'min', name: '最小值'}
                        ]
                    },
                    markLine : {
                        lineStyle: {
                            normal: {
                                type: 'solid'
                            }
                        },
                        data : [
                            {type : 'average', name: '平均值'},
                            { xAxis: 170 }
                        ]
                    }
                }
            ]
        };

        myChart.setOption(option);
        //容器自适应
        window.onresize = myChart.resize;
    }
}]);
